import com.util.DictUtil;
            
class UserinfoController 
{
    def jdbcTmplt;
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    static allowedMethods = [save:'POST', update:'POST']

    def list = 
    {
        if(!params.max) params.max = DictUtil.PARAMSMAX;
        if(!params.offset) params.offset = 0;
        def nametj = "";
        def userinfoInstanceList = [];
        def totalRow;   
        if(params.nametj)
        	nametj = params.nametj;
        if(nametj && nametj != "")
        {
        	if(params.sort && params.order)
        	{
        		userinfoInstanceList = Userinfo.findAll("from Userinfo where username like '%${nametj}%' order by ${params.sort} ${params.order}", [max:params.max.toInteger(), offset:params.offset.toInteger()]);
        	}else
        	{
        		userinfoInstanceList = Userinfo.findAll("from Userinfo where username like '%${nametj}%'", [max:params.max.toInteger(), offset:params.offset.toInteger()]);
        	}
        	totalRow = Userinfo.executeQuery("select count(*) from Userinfo where username like '%${nametj}%'");
        	totalRow = totalRow[0];       	
        }else
        {
        	if(params.sort && params.order)
        	{
        		userinfoInstanceList = Userinfo.findAll("from Userinfo order by ${params.sort} ${params.order}", [max:params.max.toInteger(), offset:params.offset.toInteger()]);
        	}else
        	{
        		userinfoInstanceList = Userinfo.findAll("from Userinfo", [max:params.max.toInteger(), offset:params.offset.toInteger()]);
        	}
        	totalRow  = Userinfo.executeQuery("select count(*) from Userinfo");
        	totalRow = totalRow[0];
        }
        
        return [ userinfoInstanceList:userinfoInstanceList, totalRow:totalRow, nametj:nametj, max:params.max, offset:params.offset, sort:params.sort, order:params.order ]
    }
    

    def show = 
    {
        def userinfoInstance = Userinfo.get( params.id )

        if(!userinfoInstance) 
        {
            flash.message = message(code:'lxh.display.noFindMsg')
            redirect(action:list)
        }
        else { return [ userinfoInstance : userinfoInstance ] }
    }

    def delete = 
    {
        def userinfoInstance = Userinfo.get( params.id )
        if(userinfoInstance) 
        {
            userinfoInstance.delete()
            flash.message = message(code:'lxh.display.deleteMsg')
            redirect(action:list)
        }else 
        {
            flash.message = message(code:'lxh.display.noFindMsg')
            redirect(action:list)
        }
    }

    def edit = 
    {
        def userinfoInstance = Userinfo.get( params.id )

        if(!userinfoInstance) 
        {
            flash.message = message(code:'lxh.display.noFindMsg')
            redirect(action:list)
        }else 
        {
            return [ userinfoInstance : userinfoInstance ]
        }
    }

    def update = 
    {
        def userinfoInstance = Userinfo.get( params.id )
        if(userinfoInstance) 
        {
            userinfoInstance.properties = params
            if(!userinfoInstance.hasErrors() && userinfoInstance.save()) 
            {
                flash.message = message(code:'lxh.display.updateMsg')
                redirect(action:list)
            }else 
            {
                render(view:'edit',model:[userinfoInstance:userinfoInstance])
            }
        }else 
        {
            flash.message = message(code:'lxh.display.noFindMsg')
            redirect(action:edit,id:params.id)
        }
    }

    def create = 
    {
        def userinfoInstance = new Userinfo()
        userinfoInstance.properties = params
        return ['userinfoInstance':userinfoInstance]
    }

    def save = 
    {
        def userinfoInstance = new Userinfo(params)
        if(!userinfoInstance.hasErrors() && userinfoInstance.save()) 
        {
            flash.message = message(code:'lxh.display.createMsg')
            redirect(action:list)
        }else 
        {
            render(view:'create',model:[userinfoInstance:userinfoInstance])
        }
    }
    
    def delBatch = 
    {
    	def batchIds = params.batchIds;
    	jdbcTmplt.update("delete from Userinfo where id in (${batchIds})");
    	redirect(action:list);
    }
}